package com.x.erp.service;

import java.util.List;

import com.x.erp.manage.ShopManage;
import com.x.erp.model.User;
import com.x.erp.rpc.ShopRpcService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.erp.dao.ShopDao;
import com.x.erp.model.Shop;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;

@Component
@Service(interfaceName = "com.x.erp.rpc.ShopRpcService", timeout = 60000)
public class ShopService extends BaseService implements ShopRpcService {

	@Autowired
	private ShopDao shopDao;

	@Autowired
	private ShopManage shopManage;

	@Override
	public List<Shop> selectShopList(Shop shop) {
		try {
			return shopDao.selectShopList(shop);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	@Override
	public int selectShopNum(Shop shop) {
		try {
			return shopDao.selectShopNum(shop);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	@Override
	public User insertShopUser(User user) {
		try {
			return shopManage.insertShopUser(user);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	@Override
	public void updateShopUser(User user) {
		try {
			shopManage.updateShopUser(user);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	@Override
	public Integer updateShop(Shop shop) {
		try {
			return this.update(shop);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	/**
	 * 插入商铺
	 * @param shop
	 * @return Shop
	 */
	@Override
	public Shop insertShop(Shop shop) {
		try {
			return this.insert(shop);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	@Override
	public int selectPledgeShopNum(Shop shop){
		try {
			return shopDao.selectPledgeShopNum(shop);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}
}
